﻿Imports Logica

Public Class ModificarCuentaContable

    Private m_descripcion As String
    Private m_saldo As Double
    Private ucConsultarCuenta As ConsultarCuentaContable

    Private Sub ModificarCuentaContable_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        lblRetroalimentacion.Text = ""
        lblRetroalimentacion.ForeColor = Color.Red

    End Sub

    ''' <summary>
    ''' Constructor Sobrecargado.
    ''' </summary>
    ''' <param name="p_codigo">Codigo.</param>
    ''' <param name="p_descripcion">Descripcion.</param>
    ''' <param name="p_saldo">Saldo.</param>
    ''' <remarks>Creado Por: Roberto Fiatt, Fecha: 15/06/2010, Modificado: 18/06/2010</remarks>
    Public Sub New(ByVal p_codigo As String, ByVal p_descripcion As String, ByVal p_saldo As Double)

        ' This call is required by the Windows Form Designer.
        InitializeComponent()

        ' Add any initialization after the InitializeComponent() call.
        txtCodigo.Text = p_codigo
        txtDescripcion.Text = p_descripcion
        txtSaldo.Text = p_saldo

        m_descripcion = p_descripcion
        m_saldo = p_saldo

        txtCodigo.ReadOnly = True

    End Sub

    ''' <summary>
    ''' Constructor Vacion.
    ''' </summary>
    ''' <remarks>Creado Por: Roberto Fiatt, Fecha: 15/06/2010, Modificado: 18/06/2010</remarks>
    Public Sub New()

        ' This call is required by the Windows Form Designer.
        InitializeComponent()

        ' Add any initialization after the InitializeComponent() call.

    End Sub

    ''' <summary>
    ''' Accion del boton de aceptar.
    ''' </summary>
    ''' <remarks>Creado Por: Roberto Fiatt, Fecha: 15/06/2010, Modificado: 18/06/2010</remarks>
    Private Sub btnAceptar_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnAceptar.Click

        For Each c As Control In gbModificarCuenta.Controls
            If TypeOf c Is TextBox Then
                If c.Text = "" Or c.Text.Trim = "" Then
                    c.Focus()
                    lblRetroalimentacion.ForeColor = Color.Red
                    lblRetroalimentacion.Text = "El campo '" & c.Tag & "' está vacío."
                    Exit Sub
                End If
            End If
        Next


        Try
            Gestor.modificarCuenta(txtCodigo.Text, txtDescripcion.Text, txtSaldo.Text)
            lblRetroalimentacion.ForeColor = Color.Green
            lblRetroalimentacion.Text = "Se ha modificado con éxito."
            txtDescripcion.Text = ""
            txtSaldo.Text = ""
        Catch sqlEx As SqlClient.SqlException
            lblRetroalimentacion.ForeColor = Color.Red
            lblRetroalimentacion.Text = "Error de Conexión."
        Catch ex As Exception
            MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
        End Try

    End Sub
    ''' <summary>
    ''' Accion del boton de cancelar.
    ''' </summary>
    ''' <remarks>Creado Por: Roberto Fiatt, Fecha: 15/06/2010, Modificado: 18/06/2010</remarks>
    Private Sub btnCancelar_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCancelar.Click
        Dim config As Configuracion
        Dim ubicacion As New Point(152, 0)

        ucConsultarCuenta = New ConsultarCuentaContable
        ucConsultarCuenta.Location = ubicacion

        config = Me.Parent
        config.Controls.Add(ucConsultarCuenta)
        config.mostrarControl(ucConsultarCuenta)
        config.tvConfiguracion.SelectedNode = config.tvConfiguracion.Nodes("ndConsultar")
    End Sub
    ''' <summary>
    ''' Accion que con el cambio del campo saldo este valide que sea solo numerico.
    ''' </summary>
    ''' <remarks>Creado Por: Roberto Fiatt, Fecha: 15/06/2010, Modificado: 18/06/2010</remarks>
    Private Sub txtSaldo_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txtSaldo.TextChanged
        If Not IsNumeric(txtSaldo.Text) Then
            txtSaldo.Text = ""
        End If
    End Sub
    ''' <summary>
    ''' Limpia los campos modificables.
    ''' </summary>
    ''' <remarks>Creado Por: Roberto Fiatt, Fecha: 15/06/2010, Modificado: 28/06/2010</remarks>
    Private Sub btnLimpiar_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnLimpiar.Click
        txtDescripcion.Text = ""
        txtSaldo.Text = ""
        lblRetroalimentacion.Text = ""
    End Sub
End Class
